package test;

import io.github.loserYa.enable.EnableMqLog;
import io.github.loserYa.enable.EnableRegister;
import io.github.loserYa.utils.LogUtils;
import io.github.loserYa.utils.RabbitMqUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;

import java.util.Arrays;
import java.util.Date;

@SpringBootApplication(exclude = RabbitAutoConfiguration.class)
@EnableMqLog
@EnableRegister(pre = {"user", "room"})
public class RestTestApplication {

    /**
     * 唯一启动类
     *
     * @param args 程序参数
     */
    public static void main(String[] args) throws InterruptedException {

        SpringApplication.run(RestTestApplication.class, args);
        RabbitTemplate user = RabbitMqUtil.get("user");
        RabbitTemplate room = RabbitMqUtil.get("room");
        RabbitTemplate log = RabbitMqUtil.get("log");
        RabbitTemplate log1 = RabbitMqUtil.get("log");
        RabbitTemplate room1 = RabbitMqUtil.get("room");
        RabbitTemplate user1 = RabbitMqUtil.get("user");
        System.out.println(111);

        while (true) {

            // 保存单条数据
            LogUserLogin login = new LogUserLogin();
            login.setUpdateDate(new Date());
            login.setUsername("loser");
            login.setDate(new Date());
            LogUtils.push(login);

            // 批量保存
            LogUtils.batchPush(Arrays.asList(login, login, login));

            // 更新数据
            LogUserLogin update = new LogUserLogin();
            update.setUsername("loser");
            update.setUpdateDate(new Date());

            LogUserLogin condition = new LogUserLogin();
            condition.setUpdateDate(new Date());
            condition.setId(System.currentTimeMillis());

            LogUtils.update(update, condition);

            System.out.println("==================");
            Thread.sleep(5000L);
        }

    }

}